<?php
import("@.Validator.OrganizationValidator");
import("@.Model.OrganizationModel");

class OrganizationAction extends Action
{
    //创建组织
    public function createOrganization($userId,$province,$city,$university,$orgName,$orgDesc,$orgType)
    {
        //验证userid
        $condition['id']=$userId;
        $condition['disable']=1;
        $UserPsd = new UserModel();
        $userResult = $UserPsd->where($condition)->count();
        //echo $UserPsd->getLastSql();
        if($userResult!=1)
        {
            //不存在该userid
            $this->ajaxReturn(output_json_fail('80011',''));
        }

        //插入
        $orgData = array();
        $orgData['userId'] = $userId;
        $orgData['province'] = $province;
        $orgData['city'] = $city;
        $orgData['university'] = $university;
        $orgData['orgName'] = $orgName;
        $orgData['orgType'] = $orgType;
        $orgData['orgDesc'] = $orgDesc;
        //$Org = M('Organization');
        $Org = new OrganizationModel();
        //$Org = new Model('Organization');
        $Org->create($orgData);
        //$Org->data($orgData);
        $Org->add();
        //echo $Org->getLastSql();
        $this->ajaxReturn(output_json_success('0'));
    }


    public function modifyOrganization( $userId, $orgId, $province='', $city='',
                                       $university='', $orgName='', $orgDesc='', $orgType='',
                                       $picUrl='' )
    {
        //验证userid
        $condition['id']=$userId;
        $condition['disable']=1;
        $UserPsd = new UserModel();
        $userResult = $UserPsd->where($condition)->count();
        //echo $UserPsd->getLastSql();
        if($userResult!=1)
        {
            //不存在该userid
            $this->ajaxReturn(output_json_fail('80011',''));
        }

        //更新组织信息
        $orgData['id'] = $orgId;
        //$orgData['userId'] = $userId;
        $orgData['province'] = $province;
        $orgData['city'] = $city;
        $orgData['university'] = $university;
        $orgData['orgName'] = $orgName;
        $orgData['orgType'] = $orgType;
        $orgData['orgDesc'] = $orgDesc;
        //$orgData['pic_url'] = $picUrl;//暂缺
        foreach ($orgData as $key=>$value)
        {
            if($value==''){
                unset($orgData[$key]);
            }
        }

        $Org = new OrganizationModel();
        //$Org = M('Organization');
        //$Org->validate(OrganizationValidator::getCreateOrgRules())->create($orgData);
        //$Org->data($orgData)->save();
        //$Org->save($orgData);
        $Org->create($orgData);
        $Org->save();
        //echo $Org->getLastSql();
        $this->ajaxReturn(output_json_success('0'));
    }
}

?>